package com.tutou.ikgroup.controller;

import com.tutou.ikgroup.pojo.dto.FriendDTO;
import com.tutou.ikgroup.service.UserFriend;
import com.tutou.ikuser.pojo.dto.Result;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.tutou.ikuser.util.RedisConstants.LOGIN_TOKEN_KEY;

@RestController
@RequestMapping("/friend")
public class UserFriendController {

    @Autowired
    private UserFriend userFriend;

    @PostMapping("/addFriend")
    public Result addFriend(@RequestHeader("Authorization") String token, @RequestBody FriendDTO friendDTO) {
        return userFriend.addFriend(LOGIN_TOKEN_KEY + token, friendDTO);
    }

    @PostMapping("/passOrRejectFriend")
    public Result passOrRejectFriend(@RequestHeader("Authorization") String token, @RequestBody FriendDTO friendDTO) {
        return userFriend.passOrRejectFriend(token, friendDTO);
    }

    @GetMapping("/friendRequestList/{userId}")
    public Result getFriendRequestList(@PathVariable("userId") String userId) {
        return userFriend.getFriendRequestList(userId);
    }

    @GetMapping("/friendList")
    public Result getFriendList(@RequestHeader("Authorization") String token) {
        return userFriend.getFriendList(LOGIN_TOKEN_KEY + token);
    }

    @DeleteMapping("/delete")
    public Result deleteFriend(@RequestHeader("Authorization") String token, @RequestBody FriendDTO friendDTO) {
        return userFriend.deleteFriend(LOGIN_TOKEN_KEY + token, friendDTO);
    }
}
